﻿using SqlPerfomance.V2.DomainModel;
using SqlPerfomance.V2.DomainModel.Enums;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SqlPerfomance.V2.DAL
{
    public class DatabaseLogger
    {
        static DatabaseLogger()
        {
            try
            {
                string dirName = string.Format(@"{0}", AppSettingsHelper.LogDirectoryName);
                if (Directory.Exists(dirName))
                    Directory.Delete(dirName, true);
                Directory.CreateDirectory(dirName);
            }catch(Exception ex)
            {
                
            }
        }

        public void Log(ConnectionStrings connectionString, string sqlForLog, string fileName)
        {
            string dirName = string.Format(@"{0}\{1}", AppSettingsHelper.LogDirectoryName, connectionString.ToString());
            if (!Directory.Exists(dirName))
                Directory.CreateDirectory(dirName);
            string filePath = Path.Combine(dirName, fileName + ".txt");
            if (File.Exists(filePath)) File.Delete(filePath);
            File.AppendAllText(filePath, sqlForLog);
        }
    }
}
